import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/binding/widget/upload_image.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/modal/modal.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

Future<Map<String, dynamic>> showEditCouponShareModal(BuildContext context, String title, String imageUrl) {
  return showModal(
    context,
    builder: (ctx) => _EditCouponShareModal(title, imageUrl),
  );
}

class _EditCouponShareModal extends StatefulWidget {
  final title;
  final imageUrl;

  const _EditCouponShareModal(this.title, this.imageUrl);

  @override
  __EditCouponShareModalState createState() => __EditCouponShareModalState();
}

class __EditCouponShareModalState extends State<_EditCouponShareModal> {
  final OutlineInputBorder _inputBorder = OutlineInputBorder(
    borderSide: BorderSide(
      color: ColorConstant.e5e5,
      width: 1.px * 2,
    ),
    borderRadius: BorderRadius.circular(
      10.w,
    ),
  );

  String title;
  String imageUrl;

  @override
  void initState() {
    super.initState();

    title = widget.title;
    imageUrl = widget.imageUrl;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 640.w,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            padding: EdgeInsets.symmetric(horizontal: 50.w),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(
                    top: 40.w,
                    bottom: 30.w,
                  ),
                  child: Text(
                    '编辑分享页',
                    style: TextStyleConstant().normal_1_28,
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(
                    bottom: 30.w,
                  ),
                  child: TextFormField(
                    keyboardAppearance: Brightness.light,
                    decoration: InputDecoration(
                      enabledBorder: _inputBorder,
                      focusedBorder: _inputBorder,
                      hintText: '请输入分享标题',
                      hintStyle: TextStyleConstant().normal_4_28,
                      contentPadding: EdgeInsets.symmetric(
                        vertical: 25.w,
                        horizontal: 20.w,
                      ),
                    ),
                    style: TextStyleConstant().normal_1_28,
                    initialValue: title,
                    onChanged: (value) {
                      setState(() {
                        title = value;
                      });
                    },
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(bottom: 50.w),
                  child: UploadImage(
                    height: 430.w,
                    uploadedImage: imageUrl,
                    onUploaded: (imageUrl) {
                      setState(() {
                        this.imageUrl = imageUrl;
                      });
                    },
                  ),
                ),
              ],
            ),
          ),
          Column(
            children: <Widget>[
              Container(
                padding: EdgeInsets.symmetric(
                  horizontal: 20.w,
                ),
                child: CustomDivider(),
              ),
              Container(
                height: 100.w,
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          Navigator.pop(context);
                        },
                        child: Align(
                          alignment: Alignment.center,
                          child: Text(
                            '取消',
                            style: TextStyleConstant().origin_32,
                          ),
                        ),
                      ),
                    ),
                    Container(
                      width: 1.px,
                      height: 90.w,
                      color: ColorConstant.e6e6,
                    ),
                    Expanded(
                      child: GestureDetector(
                        onTap: () {
                          if (title == null || title == '') {
                            toast('请输入分享标题');
                            return;
                          }

                          if (title.length > 25) {
                            toast('分享标题长度不能大于25位');
                            return;
                          }

                          if (imageUrl == null) {
                            toast('请上传分享图片');
                            return;
                          }

                          Navigator.pop(context, {
                            'title': title,
                            'imageUrl': imageUrl,
                          });
                        },
                        behavior: HitTestBehavior.translucent,
                        child: Align(
                          alignment: Alignment.center,
                          child: Text(
                            '确定',
                            style: TextStyleConstant().blue_32,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          )
        ],
      ),
    );
  }
}
